package com.crc.luojian.constant;

import lombok.Data;

import java.util.Properties;

/**
 * @program: luojian-springframework
 * @description:
 * @author: luojian58
 * @create: 2021-06-14 10:36
 */
@Data
public class DBProperties {

    /* 链接属性 */
    private String driverName ;

    private String url ;

    private String userName;

    private String password;

    private String poolName;// 连接池名字

    private int minConnections ; // 空闲池，最小连接数

    private int maxConnections ; // 空闲池，最大连接数

    private int initConnections;// 初始化连接数

    private long connTimeOut ;// 重复获得连接的频率 1s  重复连接数据库时间

    private int maxActiveConnections ;// 最大允许的连接数，和数据库对应

    private long connectionTimeOut;// 连接超时时间，默认20分钟  网络请求超时

    private long maxIdleTime;

    public DBProperties(Properties properties){
        this.driverName = (String) properties.get(ConfigConstant.JDBC_DRIVER);
        this.url = properties.getProperty(ConfigConstant.JDBC_URL);
        this.userName = properties.getProperty(ConfigConstant.JDBC_USERNAME);
        this.password = properties.getProperty(ConfigConstant.JDBC_PASSWORD);
        this.driverName = (String) properties.get(ConfigConstant.JDBC_DRIVER);
        this.poolName = properties.getProperty(ConfigConstant.JDBC_POOLNAME);
        this.minConnections = Integer.valueOf(properties.getProperty(ConfigConstant.JDBC_min_Connections));
        this.maxConnections =  Integer.valueOf(properties.getProperty(ConfigConstant.JDBC_max_Connections));
        this.initConnections =  Integer.valueOf(properties.getProperty(ConfigConstant.JDBC_init_Connections));
        this.connTimeOut = Long.parseLong(properties.getProperty(ConfigConstant.JDBC_connTimeOut));
        this.maxActiveConnections = Integer.parseInt(properties.getProperty(ConfigConstant.JDBC_max_ActiveConnections));
        this.connectionTimeOut = Long.parseLong(properties.getProperty(ConfigConstant.JDBC_connection_TimeOut));
        this.maxIdleTime = Long.parseLong(properties.getProperty(ConfigConstant.JDBC_max_IdleTime));
    }
}
